package o;

import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.drm.DrmInitData;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import com.huawei.hms.support.api.entity.core.JosStatusCodes;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.nio.ByteBuffer;
import java.util.Arrays;

public final class acn {
    private static final int[] ˋ = new int[]{64, 112, DnsConfig.MAX_CACHE_ENTRIES, 192, 224, 256, 384, 448, WXMediaMessage.TITLE_LENGTH_LIMIT, 640, 768, 896, WXMediaMessage.DESCRIPTION_LENGTH_LIMIT, 1152, 1280, 1536, 1920, 2048, 2304, 2560, 2688, 2816, 2823, 2944, 3072, 3840, 4096, 6144, 7680};
    private static final int[] ˎ = new int[]{1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8};
    private static final int[] ॱ = new int[]{-1, JosStatusCodes.RTN_CODE_COMMON_ERROR, 16000, 32000, -1, -1, 11025, 22050, 44100, -1, -1, 12000, 24000, 48000, -1, -1};

    public static boolean ॱ(int i) {
        return i == 2147385345 || i == -25230976 || i == 536864768 || i == -14745368;
    }

    public static Format ˋ(byte[] bArr, String str, String str2, DrmInitData drmInitData) {
        int i;
        ane ˋ = ˋ(bArr);
        ˋ.ˎ(60);
        int i2 = ˎ[ˋ.ॱ(6)];
        int i3 = ॱ[ˋ.ॱ(4)];
        int ॱ = ˋ.ॱ(5);
        ॱ = ॱ >= ˋ.length ? -1 : (ˋ[ॱ] * 1000) / 2;
        ˋ.ˎ(10);
        if (ˋ.ॱ(2) > 0) {
            i = 1;
        } else {
            i = 0;
        }
        return Format.ˎ(str, "audio/vnd.dts", null, ॱ, -1, i2 + i, i3, null, drmInitData, 0, str2);
    }

    public static int ˊ(byte[] bArr) {
        int i;
        switch (bArr[0]) {
            case (byte) -2:
                i = ((bArr[5] & 1) << 6) | ((bArr[4] & 252) >> 2);
                break;
            case (byte) -1:
                i = ((bArr[4] & 7) << 4) | ((bArr[7] & 60) >> 2);
                break;
            case (byte) 31:
                i = ((bArr[5] & 7) << 4) | ((bArr[6] & 60) >> 2);
                break;
            default:
                i = ((bArr[4] & 1) << 6) | ((bArr[5] & 252) >> 2);
                break;
        }
        return (i + 1) * 32;
    }

    public static int ˎ(ByteBuffer byteBuffer) {
        int position = byteBuffer.position();
        switch (byteBuffer.get(position)) {
            case (byte) -2:
                position = ((byteBuffer.get(position + 4) & 252) >> 2) | ((byteBuffer.get(position + 5) & 1) << 6);
                break;
            case (byte) -1:
                position = ((byteBuffer.get(position + 7) & 60) >> 2) | ((byteBuffer.get(position + 4) & 7) << 4);
                break;
            case (byte) 31:
                position = ((byteBuffer.get(position + 6) & 60) >> 2) | ((byteBuffer.get(position + 5) & 7) << 4);
                break;
            default:
                position = ((byteBuffer.get(position + 5) & 252) >> 2) | ((byteBuffer.get(position + 4) & 1) << 6);
                break;
        }
        return (position + 1) * 32;
    }

    public static int ˎ(byte[] bArr) {
        int i;
        int i2 = 0;
        switch (bArr[0]) {
            case (byte) -2:
                i = ((((bArr[4] & 3) << 12) | ((bArr[7] & 255) << 4)) | ((bArr[6] & 240) >> 4)) + 1;
                break;
            case (byte) -1:
                i = ((((bArr[7] & 3) << 12) | ((bArr[6] & 255) << 4)) | ((bArr[9] & 60) >> 2)) + 1;
                i2 = 1;
                break;
            case (byte) 31:
                i = ((((bArr[6] & 3) << 12) | ((bArr[7] & 255) << 4)) | ((bArr[8] & 60) >> 2)) + 1;
                i2 = 1;
                break;
            default:
                i = ((((bArr[5] & 3) << 12) | ((bArr[6] & 255) << 4)) | ((bArr[7] & 240) >> 4)) + 1;
                break;
        }
        return i2 != 0 ? (i * 16) / 14 : i;
    }

    private static ane ˋ(byte[] bArr) {
        if (bArr[0] == Byte.MAX_VALUE) {
            return new ane(bArr);
        }
        byte[] copyOf = Arrays.copyOf(bArr, bArr.length);
        if (ॱ(copyOf)) {
            for (int i = 0; i < copyOf.length - 1; i += 2) {
                byte b = copyOf[i];
                copyOf[i] = copyOf[i + 1];
                copyOf[i + 1] = b;
            }
        }
        ane o_ane = new ane(copyOf);
        if (copyOf[0] == (byte) 31) {
            ane o_ane2 = new ane(copyOf);
            while (o_ane2.ˏ() >= 16) {
                o_ane2.ˎ(2);
                o_ane.ॱ(o_ane2.ॱ(14), 14);
            }
        }
        o_ane.ˏ(copyOf);
        return o_ane;
    }

    private static boolean ॱ(byte[] bArr) {
        return bArr[0] == (byte) -2 || bArr[0] == (byte) -1;
    }
}
